package com.yk.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yk.common.annotation.Log;
import com.yk.common.enums.BusinessType;
import com.yk.points.domain.PointsAmount;
import com.yk.points.service.IPointsAmountService;
import com.yk.common.core.controller.BaseController;
import com.yk.common.core.domain.AjaxResult;
import com.yk.common.utils.poi.ExcelUtil;
import com.yk.common.core.page.TableDataInfo;
import org.springframework.stereotype.Controller;

/**
 * 金额兑换积分Controller
 * 
 * @author xufei
 * @date 2025-04-28
 */
@Controller
@RequestMapping("/points/pointsAmount")
public class PointsAmountController extends BaseController
{
    private String prefix = "points/pointsAmount";

    @Autowired
    private IPointsAmountService pointsAmountService;

    @RequiresPermissions("points:pointsAmount:view")
    @GetMapping()
    public String pointsAmount()
    {
        return prefix + "/pointsAmount";
    }

    /**
     * 查询金额兑换积分列表
     */
    @RequiresPermissions("points:pointsAmount:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PointsAmount pointsAmount)
    {
        startPage();
        List<PointsAmount> list = pointsAmountService.selectPointsAmountList(pointsAmount);
        return getDataTable(list);
    }

    /**
     * 导出金额兑换积分列表
     */
    @RequiresPermissions("points:pointsAmount:export")
    @Log(title = "金额兑换积分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PointsAmount pointsAmount)
    {
        List<PointsAmount> list = pointsAmountService.selectPointsAmountList(pointsAmount);
        ExcelUtil<PointsAmount> util = new ExcelUtil<PointsAmount>(PointsAmount.class);
        return util.exportExcel(list, "金额兑换积分数据");
    }

    /**
     * 新增金额兑换积分
     */
    @RequiresPermissions("points:pointsAmount:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存金额兑换积分
     */
    @RequiresPermissions("points:pointsAmount:add")
    @Log(title = "金额兑换积分", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PointsAmount pointsAmount)
    {
        return toAjax(pointsAmountService.insertPointsAmount(pointsAmount));
    }

    /**
     * 修改金额兑换积分
     */
    @RequiresPermissions("points:pointsAmount:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PointsAmount pointsAmount = pointsAmountService.selectPointsAmountById(id);
        mmap.put("pointsAmount", pointsAmount);
        return prefix + "/edit";
    }

    /**
     * 修改保存金额兑换积分
     */
    @RequiresPermissions("points:pointsAmount:edit")
    @Log(title = "金额兑换积分", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PointsAmount pointsAmount)
    {
        return toAjax(pointsAmountService.updatePointsAmount(pointsAmount));
    }

    /**
     * 删除金额兑换积分
     */
    @RequiresPermissions("points:pointsAmount:remove")
    @Log(title = "金额兑换积分", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(pointsAmountService.deletePointsAmountByIds(ids));
    }
}
